package com.zjitc.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.zjitc.po.Country;
import com.zjitc.service.CountryService;

import java.util.List;
import javax.naming.NamingEnumeration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/26 15:52
 * @description:
 */
@Controller
public class CountryController {

  @Autowired
  private CountryService countryService;

  @RequestMapping("/findAllCountries")
  public void findAll(){
    List<Country> list=countryService.findAll();
    StringBuilder builder= new StringBuilder();
    for (Country country:list){
      builder.append(country.toString());
      builder.append("\n");
    }
    System.out.println(builder);
  }

  @RequestMapping("/findPage")
  public void findPageCountry(
      @RequestParam(name="start",required =false,defaultValue = "1")int start,
      @RequestParam(name ="count",required =false,defaultValue = "10")int count
  ){
    List<Country> list=countryService.findCountry(start,count);
    StringBuilder builder= new StringBuilder();
    for (Country country:list){
      builder.append(country.toString());
      builder.append("\n");
    }
    System.out.println(builder);

    System.out.println((Page) list);

    PageInfo info=new PageInfo(list);
    System.out.println(info);
  }


  @RequestMapping("/name")
  @ResponseBody
  public String getName(){
        return "name=wxh";
  }

}
